import 'package:flutter/material.dart';
import 'package:flutter_base/19_name_route_pop/registerOne.dart';
import 'package:flutter_base/19_name_route_pop/registerThree.dart';
import 'package:flutter_base/19_name_route_pop/registerTwo.dart';

void main() {
  runApp(MaterialApp(
    title: '命名路由返回',
    theme: ThemeData(
      primarySwatch: Colors.red,
      appBarTheme: const AppBarTheme(
        centerTitle: true,
      ),
    ),
    // home: const HomePage(),
    initialRoute: '/',
    routes: {
      '/': (context) => const HomePage(),
      '/one': (context) => const RegisterOne(),
      '/two': (context) => const RegisterTwo(),
      '/three': (context) => const RegisterThree(),
    },
  ));
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text('这是首页'),
      ),
      body: ElevatedButton(
          onPressed: () {
            Navigator.of(context).pushNamed('/one');
          },
          child: const Text('注册')),
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print('----------------');
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
